import Login from'@/components/Login'
import index from'@/components/index'
import yezhuloudong from '@/components/yezhu-loudong'
import yezhufangwu from '@/components/yezhu-fangwu'
import yezhuInfo from '@/components/yezhu-Info'
import yezhufangwu2 from '@/components/yezhu-fangwu2'
import jiaofeidingdan from '@/components/jiaofeidingdan'
import jiaofei from '@/components/jiaofei'
import jiaofeilishi from '@/components/jiaofeilishi'
import RepairMaster from '@/components/RepairMaster'

export function generateIndexRouter(data) {
    let indexRouter = [
      {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: Login
    },
    {
              path: '/index',
              name: 'index',
              component:index,
              meta: { title: '首页' },
              children: [
                
  {
    path:'/yezhu/loudong',
    component:yezhuloudong,
    meta:{
      title:''
    }
  },
  {
    path:'/yezhu/fangwu',
    component:yezhufangwu,
  },
  {
    path:'/yezhu/Info',
    component:yezhuInfo,
  },
  {
    path:'/yezhu/fangwu2',
    component:yezhufangwu2,
  },
  {
    path:'/feiyong/dingdan',
    component:jiaofeidingdan,
  },
  {
    path:'/feiyong/jiaofei',
    component:jiaofei,  
  },
  {
    path:'/feiyong/jiaofeilishi',
    component:jiaofeilishi,
  },
  {
    path:'/repairs/RepairMaster/:id',
    component:RepairMaster,
  },
                ...generateChildRouters(data)
              ]
            }]
      return indexRouter;
}



function  generateChildRouters (data) {
        console.log("generateChildRouters方法");
        const routers = []
        for (let item of data) {

          let menu =  {
            path: item.url,
            component:
            // getViews(item.component),
            // ()=> import(`@/views/${com}.vue`),
            (resolve) => require([`@/components/${item.component}.vue`], resolve),
            // hidden:item.hidden,
            meta: {
              title:item.name ,
              // url:item.meta.url ,
              // permissionList:item.meta.permissionList,
         
            }
          }
          if (item.chie && item.chie.length > 0) {
            menu.children = [...generateChildRouters( item.chie)];
          }
            routers.push(menu);
        }
        return routers
      }    

      // function getViews(path) {
      //   return resolve => {
      //     require.ensure([], (require) => {
      //       resolve(require('@/views/' + path + '.vue'))
      //     })
      //   }
      // }
